package com.aisoback.controller;

import com.aisoback.common.BaseResponse;
import com.aisoback.common.ResultUtils;
import com.aisoback.model.Posts;
import com.aisoback.model.dto.SavePostDTO;
import com.aisoback.model.vo.QueryPostsVO;
import com.aisoback.service.PostsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/post")
@Slf4j
//@CrossOrigin(origins = "*")
public class PostController {
    @Resource
    private PostsService postsService;

    /**
     * 新增帖子
     *
     * @param save
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Integer> addPost(@RequestBody SavePostDTO save) {
        int Result = postsService.addPost(save);
        return ResultUtils.success(Result);
    }

    /**
     * 分页查询
     *
     * @param queryPostsVO
     * @return
     */
    @PostMapping("/page")
    public BaseResponse<Page<Posts>> getPostPage(@RequestBody QueryPostsVO queryPostsVO) {
        Integer pageNum = queryPostsVO.getPageNum();
        Integer pageSize = queryPostsVO.getPageSize();
        Page<Posts> postsList = postsService.getPostPage(queryPostsVO, pageNum, pageSize);
        return ResultUtils.success(postsList);
    }

}
